<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            background-color: cadetblue;
        }

        li {
            border: 1px solid black;
        }
    </style>
    <script>
        window.onload = function () {
            // var obj = document.querySelectorAll('li');
            // for (var x of obj) {
            //     x.onclick = function () {
            //         console.log(this.innerText);//事件源

            //     }
            // }

            document.querySelector('ul').onclick = function (event) {
                    console.log(this.innerText);//此时事件源表示ul标签
                    console.log(event.target.innerText);//表示事件触发最原始的对象
                    
            }
        }
        function index() {
            var a = document.createElement('li')
            a.innerText = '6'
            document.querySelector('ul').appendChild(a);
        }

    </script>
</head>

<body>
    <button onclick="index()">点我</button>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
</body>

</html>